<?php
namespace app\massage\model;

use app\BaseModel;
use think\facade\Db;

class CarType extends BaseModel
{
    //定义表名
    protected $name = 'shequshop_car_cartype';






    /**
     * @author chenniang
     * @DataTime: 2020-09-29 11:04
     * @功能说明:添加
     */
    public function dataAdd($data){

        $data['create_time'] = time();

        $res = $this->insert($data);

        return $res;

    }



    /**
     * @author chenniang
     * @DataTime: 2020-09-29 11:05
     * @功能说明:编辑
     */
    public function dataUpdate($dis,$data){

        $res = $this->where($dis)->update($data);

        return $res;

    }


    /**
     * @author chenniang
     * @DataTime: 2020-09-29 11:06
     * @功能说明:列表
     */
    public function dataList($dis,$page=10){

        $data = $this->where($dis)->order('top desc,id desc')->paginate($page)->toArray();

        return $data;

    }


    /**
     * @author chenniang
     * @DataTime: 2020-09-29 11:43
     * @功能说明:
     */
    public function dataInfo($dis){

        $data = $this->where($dis)->find();

        return !empty($data)?$data->toArray():[];

    }


    /**
     * @param $id
     * @param $user
     * @功能说明:判断类型 专业还是普通
     * @author chenniang
     * @DataTime: 2021-09-28 16:55
     */
    public function getType($id,$user_id){

        $data = $this->dataInfo(['id'=>$id]);
        //如果动过数据库 一律判断为普通
        if(empty($data)){

            return 1;
        }
        //如果即选过 专业和普通 就判断用户当前身份
        if(!empty($data['major'])&&!empty($data['norm'])){

            $driver_model = new CarDriver();

            $user = $driver_model->dataInfo(['user_id'=>$user_id,'status'=>2]);

            if(!empty($user)){

                return 2;

            }else{

                return 1;
            }

        }else{
            //就根据车型身份勾选来

            $res = !empty($data['major'])?2:1;

            return $res;

        }


    }







}